Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to math-comp/math-comp#1125 #1271

Closed
wants to merge 1 commit into from
Closed

Adapt to math-comp/math-comp#1125 #1271

wants to merge 1 commit into from

Conversation

pi8027
Copy link
Member

@pi8027 pi8027 commented Jul 26, 2024

Motivation for this change

See math-comp/math-comp#1125.

Checklist
  • added corresponding entries in CHANGELOG_UNRELEASED.md
  • added corresponding documentation in the headers

Reference: How to document

Reminder to reviewers

@pi8027
Copy link
Member Author

pi8027 commented Jul 26, 2024

After spending two full days (mostly on recompiling stuff), I managed to adapt Analysis to math-comp/math-comp#1125. Most issues have been fixed on the MathComp side. However, it seems that I happened to break the mechanism to automatically prove positivity conditions like 0 < _ / _, and I couldn't find where it is implemented (couldn't find mulr_gt0 declared as a hint, for example).

@affeldt-aist
Copy link
Member

However, it seems that I happened to break the mechanism to automatically prove positivity conditions like 0 < _ / _, and I couldn't find where it is implemented (couldn't find mulr_gt0 declared as a hint, for example).

Isn't it the mechanism implemented in signed.v? @proux01

@proux01
Copy link
Collaborator

proux01 commented Jul 26, 2024

Yes, that's in thories/signed.v

@pi8027
Copy link
Member Author

pi8027 commented Jul 29, 2024

I'm taking a look at signed.v. The positivity, negativity, nullity, etc. specification of functions are expressed by the following datatypes there:

Variant nullity := NonZero | MaybeZero.

Variant sign := EqZero | NonNeg | NonPos.
Variant real := Sign of sign | AnySign.
Variant reality := Real of real | Arbitrary.

I have the impression that it should be expressed as a tuple of 4 boolean values bool * bool * bool * bool, whose elements express the possibility of the value being negative, zero, positive, and non-real. Then, the arbitrary real value would be (true, true, true, false), and arbitrary non-zero value would be (true, false, true, true).

Also, the instance for normr doesn't seem to be strong enough to prove 0 < normr x for arbitrary non-zero value x.

@@ -497,7 +497,7 @@ apply/ler_gtP => _ /posnumP[e]; rewrite ler_pdivrMr //.
have /oid /nbhs_ballP [_ /posnumP[d] dfe] := !! gt0 e.
set k := ((d%:num / 2) / (PosNum xn0)%:num)^-1.
rewrite -{1}(@scalerKV _ _ k _ x) /k // linearZZ normrZ.
rewrite -ler_pdivlMl; last by rewrite gtr0_norm.
rewrite -ler_pdivlMl; last by rewrite gtr0_norm invr_gt0.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the actual source of the issue I have is that the goal after rewrite gtr0_norm is now:

0 < idfun (d%:num / 2 / (PosNum xn0)%:num)^-1

where idfun is actually a homomorphism application:

GRing.RMorphism.sort (reverse_coercion (GRing.ssrfun_idfun__canonical__GRing_RMorphism ...) idfun)

simpl unfolds (PosNum xn0)%:num and thus is too aggressive here. Declaring a signed instance for homomorphisms would require the structures of order-preserving additive functions and ring homomorphisms, which we don't have in Mathcomp yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also expected the canonical structure inference to unfold this homomorphism application automatically, but is it because of the presence of a default instance that it does not happen?

@proux01
Copy link
Collaborator

proux01 commented Jul 29, 2024

I have the impression that it should be expressed as a tuple of 4 boolean values bool * bool * bool * bool, whose elements express the possibility of the value being negative, zero, positive, and non-real. Then, the arbitrary real value would be (true, true, true, false), and arbitrary non-zero value would be (true, false, true, true).

Sorry, could you explain what would be the advantages of such an encoding? I can clearly see the drawback of having all parameters of the same type (much higher risk to inadvertently mixing them) but not the advantages.

Also, the instance for normr doesn't seem to be strong enough to prove 0 < normr x for arbitrary non-zero value x.

Sure, feel free to strengthen it. The only thing proved is the soundness, not that we provide the best approximation.

@pi8027
Copy link
Member Author

pi8027 commented Jul 29, 2024

Sorry, could you explain what would be the advantages of such an encoding? I can clearly see the drawback of having all parameters of the same type (much higher risk to inadvertently mixing them) but not the advantages.

The current encoding doesn't seem to allow us to encode some cases, e.g., x such that (0 < x) || (x \notin Rreal). Also, there seems to be an overlap between what nullity and sign mean, e.g., I don't get what the combination of NonZero and EqZero would mean.

@pi8027
Copy link
Member Author

pi8027 commented Jul 29, 2024

bool * bool * bool * bool can be replaced with the tuple of the following four types.

Variant positivity := NonPos | MaybePos.
Variant nullity := NonZero | MaybeZero.
Variant negativity := NonNeg | MaybeNeg.
Variant reality := IsReal | MaybeNonReal.

@proux01
Copy link
Collaborator

proux01 commented Jul 31, 2024

The current encoding doesn't seem to allow us to encode some cases, e.g., x such that (0 < x) || (x \notin Rreal).

Right, that's the point of an abstraction to not be able to encode precisely everything. And indeed it could be refined if needed (but there will always be things that cannot be encoded).

I don't get what the combination of NonZero and EqZero would mean.

That's the set of values that are both non zero and equal to zero, that is the empty set (enabling to prove False).

bool * bool * bool * bool can be replaced with the tuple of the following four types.

Sure, precise types are better than boolean, but I still fail to see the details. What would be the semantics of a tuple? I would expect conjunction of individual semantics of each element, but then some encoding become uselessly redundant: for instance NonPos * MaybeReal and NonPos * IsReal represent the same thing since being NonPos implies being Real.

@pi8027
Copy link
Member Author

pi8027 commented Jul 31, 2024

For instance NonPos * MaybeReal and NonPos * IsReal represent the same thing since being NonPos implies being Real.

NonPos means x in question satisfies ~~ (0 < x), which includes the case that x is not real. (NonPos doesn't imply being real here.)

@proux01
Copy link
Collaborator

proux01 commented Jul 31, 2024

Ha, my bad, I thought it was the usual mathematical definition x <= 0. Then indeed you're probably right. Beware however that adapting all of signed.v might require quite some work.

@pi8027
Copy link
Member Author

pi8027 commented Sep 18, 2024

Since we decided to remove the new parameters of the Semilinear structure (and rename it back to Linear, see math-comp/math-comp#1125 (comment)), we no longer need this overlay PR. I'm closing it.

@pi8027 pi8027 closed this Sep 18, 2024
@pi8027 pi8027 deleted the mc_1125 branch September 18, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants